package com.alai04.android.scoreboard;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class Add1Game extends Activity {
	RadioGroup rgLord;
	RadioGroup rgBid;
	RadioGroup rgDouble;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add);
        
        TextView name;
        for (int i = 1; i <= 4; i++) {
        	name = (TextView)findViewById(R.id.lord1 + i-1);
        	name.setText(Prefs.getName(getBaseContext(), i));
        }

        RadioButton rbLord4 = (RadioButton)findViewById(R.id.lord4);
        rbLord4.setEnabled(Prefs.getPN4(getBaseContext()));
        
        RadioButton rbBid;
        for (int i = 1; i <= 3; i++) {
        	rbBid = (RadioButton)findViewById(R.id.bid1 + i-1);
        	rbBid.setEnabled(Prefs.getBID(getBaseContext()));
        }
        
        RadioButton rbDouble;
        for (int i = 0; i < 6; i++) {
        	rbDouble = (RadioButton)findViewById(R.id.double0 + i);
        	rbDouble.setEnabled(!Prefs.getPN4(getBaseContext()));
        }
        
        rgLord = (RadioGroup)findViewById(R.id.lord_group);
        rgBid = (RadioGroup)findViewById(R.id.bid_group);
        rgDouble = (RadioGroup)findViewById(R.id.double_group);
    }
    
    public void winClick(View view) {
    	Intent data = new Intent();
    	data.putExtra(ScoreViewer.KEY_LORD, rgLord.getCheckedRadioButtonId() - R.id.lord1 + 1);
    	data.putExtra(ScoreViewer.KEY_DOUBLES, rgDouble.getCheckedRadioButtonId() - R.id.double0);
    	data.putExtra(ScoreViewer.KEY_TIMES, rgBid.getCheckedRadioButtonId() - R.id.bid1 + 1);
    	data.putExtra(ScoreViewer.KEY_WIN, (view == findViewById(R.id.win)));
    	setResult(RESULT_OK, data);
    	finish();
    }
    
    public void exitClick(View view) {
    	setResult(RESULT_CANCELED);
    	finish();
    }

}
